package com.software.process.hbase


import org.apache.hadoop.hbase.{Cell, CellUtil, HBaseConfiguration,TableName}
import org.apache.hadoop.hbase.client._
import org.apache.hadoop.hbase.util.Bytes

object HBaseExample {

  def main(args: Array[String]): Unit = {
    val hconf  = HBaseConfiguration.create()
    hconf.set("hbase.zookeeper.property.clientPort", "2181");
    hconf.set("hbase.zookeeper.quorum","node01:2181");
    val conn: Connection = ConnectionFactory.createConnection(hconf)
    val table = conn.getTable(TableName.valueOf("example_table3"))
    val scan : Scan = new Scan()
    val scanner = table.getScanner(scan)
    var flag = true
    while(flag){
      val result = scanner.next()
      try{
        val cells :Array[Cell] = result.rawCells()
        cells.foreach(cell =>{
          println("行键:" + Bytes.toString(CellUtil.cloneRow(cell)))
          println("列簇:" + Bytes.toString(CellUtil.cloneFamily(cell)))
          println("列:" + Bytes.toString(CellUtil.cloneQualifier(cell)))
          println("值:" + Bytes.toString(CellUtil   .cloneValue(cell)))
        })
      }catch{
        case e:NullPointerException => flag = false
      }
    }
  }



}
